#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    int m, n, num;
    bool flag = false;
    string s;
    cin >> m;
    vector<int> stack;
    for (size_t i = 0; i < m; i++)
    {
        cin >> n;
        for (size_t j = 0; j < n; j++)
        {
            cin >> s;
            if (s == "push")
            {
                cin >> num;
                stack.push_back(num);
            }
            else if (s == "pop" && !stack.empty())
            { // pop 但栈不为空
                stack.pop_back();
            }
            else if (s == "pop" && stack.empty())
            { // pop 但栈为空
                flag = true;
            }
        }
        if (flag)
        {
            cout << "error" << endl;
            stack.clear();
            flag = false;
            continue;
        }
        else if (!stack.empty())
        {
            for (size_t k = 0; k < stack.size(); k++)
            {
                cout << stack[k] << " ";
            }
            cout << endl;
            stack.clear();
            continue;
        }
    }
    return 0;
}